﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess_Layer;
using DTO;
using System.ComponentModel;
using System.Data;

namespace Business_Layer
{
    public  class Customer_BUS
    {
        Customer_DAC cusDAC = new Customer_DAC();
        public int InsertCustomer(CustomerDTO cus)
        {
            try
            {
                cusDAC.InsertCustomer(cus);
                return 1;
            }
            catch
            {
                return 0;
            }
        }
        public IList<CustomerDTO> GetListAll()
        {
            try
            {
                return cusDAC.getListAll();
            }
            catch
            {
                throw new Exception("Không lấy được danh sách khách hàng!");
            }
        }
        public int CountList()
        {
            try
            {
                return cusDAC.CountList();
            }
            catch
            {
                throw new Exception("Error!");
            }
        }
        public static List<CustomerDTO> getAllCustomer()
        {
            return Customer_DAC.getAll();
        }

        public static bool insert(CustomerDTO newCus)
        {
            return Customer_DAC.insert(newCus);
        }
        public static bool customerIsExisted(string un)
        {
            return Customer_DAC.customerIsExisted(un);
        }
        public static CustomerDTO getByUserName(string un)
        {
            return Customer_DAC.getByUserName(un);
        }
        public static DataTable CheckSignIn(string username,string password)
        {
            List<CustomerDTO> result = new List<CustomerDTO>();

            foreach (CustomerDTO cus in Customer_DAC.getAll())
            {
                if (cus.UserName == username && cus.Password==password && !cus.IsBanned)
                {
                    result.Add(cus);
                }
            }

            return result.ToDataTable<CustomerDTO>();
        }
    }
}
